﻿using Cmp.Web.Common;
using Cmp.Web.IRepository;
using Cmp.Web.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cmp.Web.Repository
{
    public class InHospitalProvide : DbContext<InHospitalPayInfo>, IInHospitalProvide
    {
        public Task<List<InHospitalPayInfo>> GetHospitalPayInfoList(string InHospitalNumber, string PatientId, string PayTime, out ExceptionAll exception)
        {
            exception =new ExceptionAll();
            try
            {
                return Task.FromResult(Db.Queryable<InHospitalPayInfo>().Where(x => x.PatientId == PatientId && x.InHospitalNumber == InHospitalNumber && x.InHospitalPayTime == PayTime).ToList());
            }
            catch (Exception ex)
            {
                exception.errMsg = ex.Message;
                exception.Action = System.Reflection.MethodBase.GetCurrentMethod()!.Name;
                exception.errMsgId = ErrorType.MyInterfaceError;
                exception.Exception = ex;
            }
            return null;
        }

        public Task<List<PayorInHospitalPayInfo>> GetHospitalPayInfoList(string InHospitalNumber, string PatientId, string PayTime, string ItemType, out ExceptionAll exception)
        {
            exception = new ExceptionAll();
            try
            {
                return Task.FromResult(Db.Queryable<PayorInHospitalPayInfo>().Where(x => x.InHospitalNumber == InHospitalNumber && x.PatientId == PatientId && x.ItemTime == PayTime && x.ItemType == ItemType).ToList());
            }
            catch (Exception ex)
            {
                exception.errMsg = ex.Message;
                exception.Action = System.Reflection.MethodBase.GetCurrentMethod()!.Name;
                exception.errMsgId = ErrorType.MyInterfaceError;
                exception.Exception = ex;
            }
            return null;
        }

        public Task<bool> InHospitalPayment(InHospitalPayInfo inHospitalPay, out ExceptionAll exception)
        {
            exception = new ExceptionAll();
            try
            {
                return Task.FromResult(Db.Insertable<InHospitalPayInfo>(inHospitalPay).ExecuteCommand() > 0);
            }
            catch (Exception ex)
            {
                exception.errMsg = ex.Message;
                exception.Action = System.Reflection.MethodBase.GetCurrentMethod()!.Name;
                exception.errMsgId = ErrorType.MyInterfaceError;
                exception.Exception = ex;
            }
            return Task.FromResult(false);
        }
    }
}
